/*
* @Author: dengjiayao
* @Date:   2017-04-27 14:31:25
 * @Last Modified by: songwh
 * @Last Modified time: 2017-06-19 14:37:27
*/
import Pages from '../../component/pages/pages.vue'
import Answer from '../question-answer/question-answer.vue'
import Manual from '../question-manual/question-manual.vue'

import { showMsg, getAIQuestionLog } from '../../vuex/action'

export default {
  name: 'ai-question-log',
  components: {
    'vue-pages': Pages,
    'vue-answer': Answer,
    'vue-manual': Manual
  },
  vuex: {
    getters: {
      fresh: state => state.AIQuestionListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xGetList: getAIQuestionLog
    }
  },
  data() {
    return {
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      },
      form: {
        customerId: ''
      },
      showAnswer: false,
      showManual: false,
      it: ''
    }
  },
  ready() {
    this.getList({})
  },
  methods: {
    getList({start=this.pages.start, limit=this.pages.limit}) {
      var params = {
        start: start,
        limit: limit
      }
      if (this.form.customerId) {
        params.customerId = this.form.customerId
        params.resultCount = 0
      }
      this.xGetList(params)
        .then((data) => {
          this.list = data.list
          this.pages.totalPages = Math.ceil(data.count / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    searchList() {
      this.getList({
        start: 0
      })
    },
    showAnswerNoResult(item) {
      this.showAnswer= true
      this.it = item
    },
    showAnswerManual(item) {
      this.showManual= true
      this.it = item
    }
  },
  watch: {
    fresh: function(v) {
      if (v) {
        this.getList({})
      }
    }
  }
}
